package com.symbio.ishenapi.background.controller;

import com.jfinal.plugin.activerecord.Record;
import com.symbio.ishenapi.background.model.*;
import com.symbio.ishenapi.common.controller.BaseController;
import io.jboot.web.controller.annotation.RequestMapping;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName TmInsuranceController
 * @Description 保险图模块
 * @Author GuoShunYou
 * @Date 2018/11/1  上午 10:39
 **/
@RequestMapping("/TmInsuranceController")
public class TmInsuranceController<baseController> extends BaseController {


    /**
     *
     *
     * @Author GuoShunYou
     * @Description 保存推送过来的保险信息
     * @date 下午 2:44   2018/11/1
     * @return void
     */
    public void addInsuranMessage(){
        TmInsuranceMessage mess = (TmInsuranceMessage) getReqBodyObject(TmInsuranceMessage.class);
        mess.save();




    }


    /**
     *
     *
     * @Author GuoShunYou
     * @Description 根据userid、保险团id匹配险种
     * @date 上午 10:41   2018/11/1
     * @return void
     */
    public void isInsuranceUser(){
        TmInsurancorpsUser user = (TmInsurancorpsUser) getReqBodyObject(TmInsurancorpsUser.class);
        //通过userid查询所关联的险种id
        TmInsuantypeUser inuser=TmInsuantypeUser.dao.getinsuraId(user.getUserId());
        if(inuser==null){
            renderJsonError(50002,"险种匹配保险团");
            return;
        }
        Long a=inuser.getInsuranTypeId();



        //通过保险团id查询所关联的险种id
        TmInsurantypeCorps titc=TmInsurantypeCorps.dao.getTypeId(user.getInsuanCorpsId());

        if(titc==null){
            renderJsonError(50002,"险种匹配保险团");
            return;
        }
        Long b=titc.getInsuranTypeId();


        //匹配险种
        if(a==b){
            renderJsonError(50001,"险种匹配保险团");
        }else {
            renderJsonError(50002,"险种匹配保险团");
        }



    }


    /**
     *
     *
     * @Author GuoShunYou
     * @Description 通过doctorid查询当前值班的医生
     * @date 上午 10:46   2018/11/2
     * @return void
     */
    public void getdoctorId(){
        TmDoctorUser user = (TmDoctorUser) getReqBodyObject(TmDoctorUser.class);
        List<TmScheduling> lsit=TmScheduling.dao.getdocid(user.getUserType());
        if(lsit.size()<=0){
            renderJsonError(40003,"该角色当下时间对应值班医生");
        }else{
            List doctoidList=new ArrayList<>();
            for(int i=0;i<lsit.size();i++){
                BigInteger doctorid=lsit.get(i).getDoctorId();
                doctoidList.add(doctorid);
            }
            doctoidList.get(0);
            List<Record> lsituser=TmDoctorUser.dao.findTmPatientDoctorList(doctoidList.get(0).toString());
            renderJsonRet(lsituser.get(0));
        }





    }

    /**
     * wy:后台
     * 根据保险团ID查询详情
     */
    public void findById(){
        String id = getPara("id");
        String userId = getPara("userId");
        TmInsuranceCorps insuranceCorps = TmInsuranceCorps.dao.findById(id);
        TmPatientUser patientUser = TmPatientUser.dao.findById(userId);
        Map map = new HashMap();
        map.put("userId",userId);
        map.put("userName",patientUser.getUserName());
        map.put("insuranceCorpsName",insuranceCorps.getInsuranceCorpsName());
        map.put("insuranceCorpsCode",insuranceCorps.getInsuranceCorpsCode());
        map.put("insuranceCorpsId",insuranceCorps.getId());
        renderJsonRet(map);
    }
}
